//导入配置
const config=require('../CONFIG');
const jsonServer = require('json-server');
const db = require('./'+config.apiFileName);

//定义自己的路由
const port = config.apiServerPort;

const server = jsonServer.create();
const router = jsonServer.router(db.API);
const middlewares = jsonServer.defaults();
const rewriter = jsonServer.rewriter(db.Router);

server.use(middlewares);
// 将 POST 请求转为 GET
server.use((request, res, next) => {
  request.method = 'GET';
  next();
});

server.use(rewriter); // 注意：rewriter 的设置一定要在 router 设置之前
server.use(router);

server.listen(port, () => {
  console.log('#-API服务器- ######################-- server at localhost:' + port)
});